
Imports System.Data
Imports System.Data.SqlClient


Namespace Kardex
Public Class OrdenCompraProducto

public Function Listar(OrdenCompraProductoId as integer) as Entity.Kardex.OrdenCompraProducto

Dim strNameProcedure as string = "up_Kar_OrdenCompraProducto_obtener"
Dim sqlReader As SqlDataReader = Nothing
Dim sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
dim objEnt as   entity.Kardex.OrdenCompraProducto
Try
            sqlCon.Open()
Dim sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
.CommandType = CommandType.StoredProcedure
                .Parameters.Add(New SqlParameter("@OrdenCompraProductoId", SqlDbType.Int)).Value =OrdenCompraProductoId
            End With
            sqlReader = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection)
If sqlReader.HasRows Then
While sqlReader.Read
 objEnt= new    entity.Kardex.OrdenCompraProducto
With objEnt
		.OrdenCompraProductoId = sqlReader("OrdenCompraProductoId").ToString
		.ProductoId = sqlReader("ProductoId").ToString
		.Cantidad = sqlReader("Cantidad").ToString
		.PrecioUnitario = sqlReader("PrecioUnitario").ToString
		.SubTotal = sqlReader("SubTotal").ToString
		.Igv_porcentaje = sqlReader("Igv_porcentaje").ToString
		.Igv = sqlReader("Igv").ToString
		.Total = sqlReader("Total").ToString
End With
  End While
  End IF
 Catch ex As Exception
Throw New Exception(ex.ToString)
Finally
 sqlReader.Dispose()
  sqlReader.Close()
  sqlReader = Nothing
  sqlCon.Dispose()
 sqlCon.Close()
 sqlCon = Nothing
 End Try
return objEnt

End Function


'***************************



public Function Listar(Opcion as string , _
		OrdenCompraProductoId as Integer, _
		ProductoId as Integer, _
		Cantidad as Integer, _
		PrecioUnitario as Double, _
		SubTotal as Double, _
		Igv_porcentaje as Double, _
		Igv as Double, _
		Total as Double) _
as  Entity.Kardex.OrdenCompraProductoCol

Dim strNameProcedure as string = "up_Kar_OrdenCompraProducto_listar"
dim objCol as   entity.Kardex.OrdenCompraProductoCol
Try
Using conn As New SqlConnection(Configuracion.Connexion.Cnn)
Dim cmd As New SqlCommand(strNameProcedure, conn)
cmd.CommandType = CommandType.StoredProcedure
  cmd.Parameters.Add(New SqlParameter("@opcion", SqlDbType.varchar,50)).Value =Opcion
 cmd.Parameters.Add(New SqlParameter("@OrdenCompraProductoId",SqlDbType.INT)).Value =OrdenCompraProductoId
 cmd.Parameters.Add(New SqlParameter("@ProductoId",SqlDbType.INT)).Value =ProductoId
 cmd.Parameters.Add(New SqlParameter("@Cantidad",SqlDbType.INT)).Value =Cantidad
 cmd.Parameters.Add(New SqlParameter("@PrecioUnitario",SqlDbType.DECIMAL,18)).Value =PrecioUnitario
 cmd.Parameters.Add(New SqlParameter("@SubTotal",SqlDbType.DECIMAL,18)).Value =SubTotal
 cmd.Parameters.Add(New SqlParameter("@Igv_porcentaje",SqlDbType.DECIMAL,18)).Value =Igv_porcentaje
 cmd.Parameters.Add(New SqlParameter("@Igv",SqlDbType.DECIMAL,18)).Value =Igv
 cmd.Parameters.Add(New SqlParameter("@Total",SqlDbType.DECIMAL,18)).Value =Total
conn.Open()
Using dr As SqlDataReader = cmd.ExecuteReader()
		dim iOrdenCompraProductoId as integer = dr.GetOrdinal("OrdenCompraProductoId")
		dim iProductoId as integer = dr.GetOrdinal("ProductoId")
		dim iCantidad as integer = dr.GetOrdinal("Cantidad")
		dim iPrecioUnitario as integer = dr.GetOrdinal("PrecioUnitario")
		dim iSubTotal as integer = dr.GetOrdinal("SubTotal")
		dim iIgv_porcentaje as integer = dr.GetOrdinal("Igv_porcentaje")
		dim iIgv as integer = dr.GetOrdinal("Igv")
		dim iTotal as integer = dr.GetOrdinal("Total")
		dim i_usu_cre as integer = dr.GetOrdinal("_usu_cre")
		dim i_fec_cre as integer = dr.GetOrdinal("_fec_cre")
		dim i_usu_mod as integer = dr.GetOrdinal("_usu_mod")
		dim i_Fec_mod as integer = dr.GetOrdinal("_Fec_mod")
		dim i_flg_Eli as integer = dr.GetOrdinal("_flg_Eli")

 Dim colCount As Integer = dr.FieldCount
 Dim values As Object() = New Object(colCount - 1) {}

 objCol =  New entity.Kardex.OrdenCompraProductoCol
  If dr.HasRows Then
While dr.Read()
dim objEnt =  new entity.Kardex.OrdenCompraProducto
dr.GetValues(values)

		objEnt.OrdenCompraProductoId = values(iOrdenCompraProductoId)
		objEnt.ProductoId = values(iProductoId)
		objEnt.Cantidad = values(iCantidad)
		objEnt.PrecioUnitario = values(iPrecioUnitario)
		objEnt.SubTotal = values(iSubTotal)
		objEnt.Igv_porcentaje = values(iIgv_porcentaje)
		objEnt.Igv = values(iIgv)
		objEnt.Total = values(iTotal)
 objCol.Add(objEnt)
 End While
 End if
 End Using
 End Using
 Catch ex As Exception
Throw New Exception(ex.ToString)
Finally
 End Try
return objCol

End Function


'***************************


Public  Function Insert(ByVal opcion As String, _
		OrdenCompraProductoId as Integer, _
		ProductoId as Integer, _
		Cantidad as Integer, _
		PrecioUnitario as Double, _
		SubTotal as Double, _
		Igv_porcentaje as Double, _
		Igv as Double, _
		Total as Double, _
vUsuario as integer ) As Integer

 dim strNameProcedure as string ="Up_Kar_OrdenCompraProducto_Insertar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
 .Parameters.Add(New SqlParameter("@OrdenCompraProductoId",SqlDbType.INT)).Value =OrdenCompraProductoId
 .Parameters.Add(New SqlParameter("@ProductoId",SqlDbType.INT)).Value =ProductoId
 .Parameters.Add(New SqlParameter("@Cantidad",SqlDbType.INT)).Value =Cantidad
 .Parameters.Add(New SqlParameter("@PrecioUnitario",SqlDbType.DECIMAL,18)).Value =PrecioUnitario
 .Parameters.Add(New SqlParameter("@SubTotal",SqlDbType.DECIMAL,18)).Value =SubTotal
 .Parameters.Add(New SqlParameter("@Igv_porcentaje",SqlDbType.DECIMAL,18)).Value =Igv_porcentaje
 .Parameters.Add(New SqlParameter("@Igv",SqlDbType.DECIMAL,18)).Value =Igv
 .Parameters.Add(New SqlParameter("@Total",SqlDbType.DECIMAL,18)).Value =Total
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************


Public  Function Update(ByVal opcion As String, _
		OrdenCompraProductoId as Integer, _
		ProductoId as Integer, _
		Cantidad as Integer, _
		PrecioUnitario as Double, _
		SubTotal as Double, _
		Igv_porcentaje as Double, _
		Igv as Double, _
		Total as Double, _
vUsuario as integer ) As Integer

 dim strNameProcedure as string ="Up_Kar_OrdenCompraProducto_Actualizar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
 .Parameters.Add(New SqlParameter("@OrdenCompraProductoId",SqlDbType.INT)).Value =OrdenCompraProductoId
 .Parameters.Add(New SqlParameter("@ProductoId",SqlDbType.INT)).Value =ProductoId
 .Parameters.Add(New SqlParameter("@Cantidad",SqlDbType.INT)).Value =Cantidad
 .Parameters.Add(New SqlParameter("@PrecioUnitario",SqlDbType.DECIMAL,18)).Value =PrecioUnitario
 .Parameters.Add(New SqlParameter("@SubTotal",SqlDbType.DECIMAL,18)).Value =SubTotal
 .Parameters.Add(New SqlParameter("@Igv_porcentaje",SqlDbType.DECIMAL,18)).Value =Igv_porcentaje
 .Parameters.Add(New SqlParameter("@Igv",SqlDbType.DECIMAL,18)).Value =Igv
 .Parameters.Add(New SqlParameter("@Total",SqlDbType.DECIMAL,18)).Value =Total
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************


Public Shared Function Eliminar(ByVal opcion As String, OrdenCompraProductoId as integer, vusuario as integer) as integer

 dim strNameProcedure as string ="Up_Kar_OrdenCompraProducto_Eliminar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
                .Parameters.Add(New SqlParameter("@OrdenCompraProductoId", SqlDbType.Int)).Value =OrdenCompraProductoId
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************



End Class



end namespace

